﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GeckoPhotos.Models;
using GeckoPhotos.Tests.Support;
using System.IO;

namespace GeckoPhotos.Tests.TestUtil
{
    static class ImageUtil
    {

        // Values to test against and predetermine outcomes of calls to mock objects
        private const int _imageId = 6464;
        private readonly static DateTime _dateTimeCreated = DateTime.Parse("6 Apr 1964 06:40");
        private const string _caption = "Moon 64x64";
        private readonly static byte[] _blobBytes = ImageResourceBytes.Moon64x64PngBytes;
        private readonly static string _blobMimeType = "image/png";
        private readonly static byte[] _thumbnailBlobBytes = ImageResourceBytes.Moon64x64Thumbnail16x16PngBytes;
        private readonly static string _thumbnailBlobMimeType = "image/png";

        private static Image _standardImageObject;

        public static Image CreateImageObject()
        {
            User owner = UserUtil.CreateUserObject();

            Blob blob = new Blob
            {
                BlobID = 9191,
                Bytes = _blobBytes,
                MimeType = _blobMimeType,
            };

            Blob thumbnailBlob = new Blob
            {
                BlobID = 32323,
                Bytes = _thumbnailBlobBytes,
                MimeType = _thumbnailBlobMimeType,
            };

            var result = new Image
            {
                ImageID = _imageId,
                DateTimeCreated = _dateTimeCreated,
                Caption = _caption,
            };
            result.UserReference.Value = owner;
            result.BlobReference.Value = blob;
            result.ThumbnailBlobReference.Value = thumbnailBlob;

            return result;
        }

        public static Image StandardImageObject
        {
            get
            {
                if (_standardImageObject == null)
                {
                    _standardImageObject = CreateImageObject();
                }
                return _standardImageObject;
            }
        }

        public static System.Drawing.Image CreateImageFromBytes(byte[] bytes)
        {
            using (var bs = new MemoryStream(bytes))
            {
                return System.Drawing.Image.FromStream(bs);
            }
        }

    }
}
